/**   
 * @Title: UserController.java 
 * @Package com.neusoft.neumooc.controller 
 * @Description: TODO 
 * @author acer   
 * @date 2016年10月28日 下午4:53:23 
 */

package com.neusoft.neumooc.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neusoft.core.common.BaseDAO;
import com.neusoft.core.common.conf.Params;
import com.neusoft.core.util.IDUtil;
import com.neusoft.core.util.Util;
import com.neusoft.neumooc.VO.UserVO;
import com.neusoft.neumooc.service.UserInfoService;
/**
 * @ClassName: UserController
 * @Description: TODO
 * @author Fuyonjun
 * @date 2016年10月28日
 */
@Controller
@RequestMapping(value = "/users")
public class UserInfoController extends BaseDAO {
	@Autowired
	UserInfoService userInfoService;
   
	/**
	 * @Title: getUserInfos
	 * @Description: 获取用户信息
	 * @param pageNo
	 * @param pageSize
	 * @return resMap
	 */
	
	@RequestMapping(value = "/list")
	@ResponseBody
	public Map<String, Object> getUserInfos(HttpServletRequest request,HttpServletResponse response, String pageNo,String pageSize) 
	{
		int pageIndex = (Util.parseInt(pageNo) - 1) * Util.parseInt(pageSize);// 计算分页索引
		Map<String, Object> resMap = new HashMap<String, Object>();
		try {
			List<UserVO> userList = userInfoService.getUsers(pageIndex,Util.parseInt(pageSize));
			int total = userInfoService.getUserCount();// 计算分页数量
			resMap.put("total", total);
			resMap.put("userList", userList);
			resMap.put(Params.RET_CODE, Params.RET_CODE_SUCCESS);
		} catch (Exception e) {
			log.error("获取数据有异常信息抛出:" + e.getMessage(), e.getCause());
			resMap.put(Params.RET_CODE, Params.RET_CODE_ERROR);
		}
		return resMap;
	}
	
	@RequestMapping(value = "/insert")
	@ResponseBody
	public Map<String, Object> InsertUserInfos(UserVO userVO) 
	{
		Map<String, Object> resMap = new HashMap<String, Object>();
		try { 	
			if(userInfoService.checkRepeat(userVO.getUserName())!=false&&userInfoService.insertUsers(userVO)>0&&userVO.getUserName()!="")
			{    
				resMap.put(Params.RET_CODE, Params.RET_CODE_SUCCESS); 
			    resMap.put(Params.RET_MSG, "用户名提交成功");
				
			}
			else
			{
				resMap.put(Params.RET_CODE, Params.RET_CODE_ERROR); 
			    resMap.put(Params.RET_MSG, "用户名提交失败,用户名不能重复,且用户名不能为空");
			}
		} catch (Exception e) {
			log.error("获取数据有异常信息抛出:" + e.getMessage(), e.getCause());
			resMap.put(Params.RET_CODE, Params.RET_CODE_ERROR);
		}
		return resMap;
	}

}